package priv.wangy.micro.common.po.http.rspn;

import com.fasterxml.jackson.annotation.JsonView;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import priv.wangy.micro.common.po.http.rspn.code.IHttpRspnEnum;
import priv.wangy.micro.common.po.http.rspn.code.SuccessEnum;
import priv.wangy.micro.common.po.http.rspn.view.DefaultView;

/**
 * @author wangy
 * @since 2023-10-12
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonView(DefaultView.class)
public class BaseHttpResponse {

    /**
     * 处理结果
     */
    private boolean result;

    /**
     * 处理结果
     */
    private String rspnCode;

    /**
     * 响应消息提示
     */
    private String rspnMsg;

    public BaseHttpResponse(IHttpRspnEnum rspn) {
        this.failure(rspn);
    }


    public void normalSuccess() {
        this.result = true;
        this.rspnCode = SuccessEnum.SUCCESS.getRspnCode();
        this.rspnMsg = SuccessEnum.SUCCESS.getRspnMsg();
    }

    public void showSuccess(String msg) {
        this.result = true;
        this.rspnCode = SuccessEnum.SHOW_SUCCESS.getRspnCode();
        this.rspnMsg = msg;
    }

    public void success(String rspnCode, String rspnMsg) {
        this.result = true;
        this.rspnCode = rspnCode;
        this.rspnMsg = rspnMsg;
    }


    public void success(IHttpRspnEnum rspn) {
        this.result = true;
        this.rspnCode = rspn.getRspnCode();
        this.rspnMsg = rspn.getRspnMsg();
    }


    public void failure(String rspnCode, String rspnMsg) {
        this.result = false;
        this.rspnCode = rspnCode;
        this.rspnMsg = rspnMsg;
    }


    public void failure(IHttpRspnEnum rspn) {
        this.result = false;
        this.rspnCode = rspn.getRspnCode();
        this.rspnMsg = rspn.getRspnMsg();
    }

    public void response(String rspnCode, String rspnMsg) {
        this.rspnCode = rspnCode;
        this.rspnMsg = rspnMsg;
    }
}
